package vip.xiaonuo.auth.modular.wechat.controller;

import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import vip.xiaonuo.auth.modular.wechat.service.AuthWechatService;
import vip.xiaonuo.common.pojo.CommonResult;

/**
 * @author zjt
 * @description
 * @date 2025/7/17 11:22
 */
@RestController
@RequestMapping("/auth/wechat")
@RequiredArgsConstructor
public class AuthWechatController {

    private final AuthWechatService authWechatService;

    /**
     * 获取OAuth链接
     *
     * @return
     */
    @GetMapping("/getOAuthUrl/{state}")
    public CommonResult<String> getOAuthUrl(@PathVariable("state") String state) {
        return CommonResult.data(authWechatService.getOAuthUrl(state));
    }

    /**
     * 检查二维码扫描状态
     *
     * @param state
     * @return
     */
    @GetMapping("/checkScanStatus/{state}")
    public CommonResult<String> checkScanStatus(@PathVariable("state") String state) {
        return CommonResult.data(authWechatService.checkScanStatus(state));
    }

    /**
     * 账号密码登录
     *
     * @param code
     * @return
     */
    @Operation(summary = "企业微信登录回调")
    @GetMapping("/doLogin")
    public CommonResult<Void> doLogin(@RequestParam("code") String code, @RequestParam("state") String state) {
        authWechatService.doLogin(code, state);
        return CommonResult.ok();
    }
}
